var MemberProduct = {
    id: "MemberProductTable",
    seItem: null,
    table: null,
    layerIndex: -1
};
MemberProduct.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: 'productId', field: 'productId', visible: false, align: 'center', valign: 'middle'},
        {title: 'status', field: 'status', visible: false, align: 'center', valign: 'middle'},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '会员账号', field: 'account', align: 'center', valign: 'middle', sortable: true, width: 120,},
        {title: '联系电话', field: 'phone', align: 'center', valign: 'middle', width: 120},
        {title: '商品名称', field: 'productName', align: 'center', valign: 'middle', sortable: true, width: 130,},
        {title: '会员等级', field: 'vipLevelName', align: 'center', valign: 'middle', sortable: true, width: 90,},
        {title: '姓名', field: 'name', align: 'center', valign: 'middle', sortable: true, width: 90,},
        {title: '性别', field: 'sex', align: 'center', valign: 'middle', sortable: true, width: 90,},
        {title: '年龄', field: 'age', align: 'center', valign: 'middle', sortable: true, width: 110,},
        {title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', sortable: true, width: 200,},
        {
            title: '操作', field: 'id', align: 'center', valign: 'middle', width: 60,
            formatter: function (value, row, index) {
                if(row.status==1) {
                    var ids = row.id + "," + row.reservationsId + "," + row.productId;
                    return '<button title="验证" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0px 5px;" onclick="MemberProduct.revision(' + "'" + ids + "'" + ')" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button>'
                }else{
                    return '-';
                }
            },
        }
    ];
    return columns;
};

MemberProduct.revision = function (ids) {//点击表格进行验证码验证
    var index = layer.open({
        type: 2,
        title: '验证',
        area: ['30%', '40%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/integralMallWeixin/revision/' + ids
    });
    this.layerIndex = index;
};

MemberProduct.check = function () {// 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        MemberProduct.seItem = selected[0];
        return true;
    }
};

MemberProduct.search = function () {//查询医生随访列表
    MemberProduct.table.refresh({query: MemberProduct.formParams()});
    //MemberProduct.total();
};

MemberProduct.total = function () {//人数统计
    var menberStatus = $("#menberStatus").val();  //验证状态
    var startCreateTime = $("#startCreateTime").val();  //开始创建时间
    var endCreateTime = $("#endCreateTime").val();  //结束创建时间
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + "/integralMallWeixin/total",
        data: {
            menberStatus: menberStatus,
            startCreateTime: startCreateTime,
            endCreateTime: endCreateTime
        },
        dataType: "json",
        success: function (data) {
            $("#planned").html(data[0].countNum);//未兑换
            $("#finished").html(data[1].countNum);//已兑换

        }
    });
};

MemberProduct.inquire = function () {//人数统计 + 表格刷新
    MemberProduct.search();
    MemberProduct.total();
};

MemberProduct.formParams = function () {//查询表单提交参数对象 @returns {{}}
    var queryData = {};
    queryData['phone'] = $("#phone").val();
    queryData['status'] = $("#menberStatus").val();
    queryData['startCreateTime'] = $("#startCreateTime").val();
    queryData['endCreateTime'] = $("#endCreateTime").val();
    return queryData;
};

MemberProduct.totalAllNumber = function (obj) {// 根据点击上面状态刷新表格
    $("#menberStatus").val(obj);
    MemberProduct.inquire();
};

MemberProduct.resetSearch = function () {//重置
    $("#startCreateTime").val("");
    $("#endCreateTime").val("");
    $("#phone").val("");
    MemberProduct.inquire();
};

MemberProduct.time = function () {//初始化赋值时间 + 请求数据
    $("#startCreateTime").val(setDateTime(new Date(), 0) + " " + "00:00:00");
    $("#endCreateTime").val(setDateTime(new Date(), 0) + " " + "23:59:59");
};
function phonePrivileges(){   //隐藏手机号
    var phonePrivileges=parent.$("#phonePrivileges").val();
    if(phonePrivileges == 2){
        $('#MemberProductTable').bootstrapTable('hideColumn', 'phone');
    }
}

$(function () {
    var defaultColunms = MemberProduct.initColumn();
    var table = new BSTable(MemberProduct.id, "/integralMallWeixin/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(MemberProduct.formParams());
    MemberProduct.table = table.init();
    MemberProduct.time();
    MemberProduct.totalAllNumber(1);
    checkDate = function () {MemberProduct.inquire();};
    $(document).on('click', '#laydate_clear,#laydate_today,#laydate_ok', function () {MemberProduct.inquire();});
    phonePrivileges();
});